package com.ryskoo.customer.vendordiscounts.service;

import com.ryskoo.customer.vendordiscounts.domain.VendorDiscountsPO;
import com.ryskoo.customer.vendordiscounts.repository.IVendorDiscountsRepository;
import com.ryskoo.framework.core.service.BasicServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class VendorDiscountsServiceImpl extends BasicServiceImpl<VendorDiscountsPO> implements IVendorDiscountsService {

	@Autowired
	private IVendorDiscountsRepository vendorDiscountsRepository;

	@PostConstruct
	public void init() {
		this.setDao(vendorDiscountsRepository);
	}


	@Override
	public VendorDiscountsPO getByVendorUuid(String vendorUuid) {
		return vendorDiscountsRepository.getByVendorUuid(vendorUuid);
	}

	@Override
	public void save(VendorDiscountsPO po) {
		VendorDiscountsPO m = this.getByVendorUuid(po.getVendorUuid());
		if(null == m){
			vendorDiscountsRepository.create(po);
		}else {
			m.setMjOpen(po.isMjOpen());
			m.setLjOpen(po.isLjOpen());
			m.setMoney1(po.getMoney1());
			m.setFree1(po.getFree1());
			m.setMoney2(po.getMoney2());
			m.setFree2(po.getFree2());
			m.setMoney3(po.getMoney3());
			m.setFree3(po.getFree3());
			m.setLjFree(po.getLjFree());
			vendorDiscountsRepository.update(m);
		}
	}
}
